package com.example.nkj.feather_android;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.widget.TextView;

import com.gcssloop.widget.ArcSeekBar;
import io.feeeei.circleseekbar.CircleSeekBar;

/**
 * Created by nkj on 18-11-10.
 */

public class fly extends AppCompatActivity {

    private ArcSeekBar mArcSeekBar_throttle;
    private ArcSeekBar mArcSeekBar_height;
    private CircleSeekBar mCircleSeekBar_direction;

    private TextView View_throttle = null;
    private TextView View_height = null;
    private TextView View_direction = null;

    int[] colors1 = {0xFF66FF99,0xFF00FF99,0xFF33FF66,0xFF00FF00,0xFFFF3333,0xFFCC0099,0xFF330033};
    int[] colors2 = {0xFF66FF99,0xFF00FF99,0xFFFF3333,0xFFCC0099};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(getSupportActionBar() != null)
        {
            getSupportActionBar().hide();
        }
        setContentView(R.layout.fly);
        //开启横屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        mArcSeekBar_throttle = (ArcSeekBar)findViewById(R.id.seekbar_throttle);
        mArcSeekBar_height = (ArcSeekBar)findViewById(R.id.seekbar_height);
        mCircleSeekBar_direction = (CircleSeekBar)findViewById(R.id.seekbar_direction);

        View_throttle = (TextView) findViewById(R.id.textView_throttle);
        View_height = (TextView) findViewById(R.id.textView_height);
        View_direction = (TextView) findViewById(R.id.textView_direction);

        mArcSeekBar_throttle.setArcColors(colors1);
        mArcSeekBar_height.setArcColors(colors2);

        mArcSeekBar_throttle.setOnProgressChangeListener(new ArcSeekBar.OnProgressChangeListener() {
            @Override
            public void onProgressChanged(ArcSeekBar seekBar, int progress, boolean isUser)
            {
                View_throttle.setText(progress+"m/s");
            }

            @Override
            public void onStartTrackingTouch(ArcSeekBar seekBar) {}

            @Override
            public void onStopTrackingTouch(ArcSeekBar seekBar) {}
        });

        mArcSeekBar_height.setOnProgressChangeListener(new ArcSeekBar.OnProgressChangeListener() {
            @Override
            public void onProgressChanged(ArcSeekBar seekBar, int progress, boolean isUser)
            {
                //final int i = seekBar.getProgress();
                //View1.setText(i+"%");
                View_height.setText(progress+"m");
            }

            @Override
            public void onStartTrackingTouch(ArcSeekBar seekBar) {}

            @Override
            public void onStopTrackingTouch(ArcSeekBar seekBar) {}
        });

        mCircleSeekBar_direction.setOnSeekBarChangeListener(new CircleSeekBar.OnSeekBarChangeListener() {
            @Override
            public void onChanged(CircleSeekBar seekbar, int curValue)
            {
                View_direction.setText(curValue+"°");
            }
        });
    }

    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        switch (keyCode)
        {
            case KeyEvent.KEYCODE_MENU:
                break;
            case KeyEvent.KEYCODE_BACK:
                startActivity(new Intent(fly.this,MainActivity.class));
                finish();
                break;
            default:
                break;
        }
        return super.onKeyDown(keyCode, event);
    }
}
